package com.monkeyboy.first.stopthreads;

/**
 * 描述：     带有sleep的中断线程的写法
 */
public class RightWayStopThreadWithSleep {

    public static void main(String[] args) throws InterruptedException {
        Runnable runnable = () -> {
            int num = 0;
            try {
                while (num <= 3000000000L && !Thread.currentThread().isInterrupted()) {
                    if (num % 100 == 0) {
                        System.out.println(num + "是100的倍数");
                    }
                    num++;
                }
                System.out.println(Thread.currentThread().isInterrupted());
                System.out.println("-------------");
                Thread.sleep(1000);
                System.out.println("============");
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println("1111------------");
            System.out.println(Thread.currentThread().isInterrupted());
        };
        Thread thread = new Thread(runnable);
        thread.start();
        Thread.sleep(500);
        thread.interrupt();
    }
}
